<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../rest.js"></script>
</head>

<body>
    <button id="btn">登录</button>
</body>

<script>

    // 函数节流  =>  如果传入的回调函数短时间内连续触发 => 降低执行的频率
    // 防抖     =>   如果传入的回调函数短时间内连续触发 => 只执行最后一次
    function debounceFn(callback, delay = 300) {
        var timer = null
        return function () {
            clearTimeout(timer)
            timer = setTimeout(function () {
                callback.apply(this, arguments)
            }, delay)
        }
    }



    
    btn.onclick = debounceFn(function () { //回调函数
        ajax({
            type: "post",
            url: "http://43.138.81.225/demo/php/login_account.php",
            data: {
                account: "a123123",
                pwd: 123123,
            },
            callback: function (result) {
                console.log(result);
            }
        })
    }, 300)


</script>

</html>